#include <iostream>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    ListNode* removeElements(ListNode* head, int val) {
        if (head == nullptr) return nullptr;
        if (head->val == val) {
            head = head->next;
            return removeElements(head, val);
        }
        head->next = _removeElements(head, val);
        return head;
    }

    ListNode* _removeElements(ListNode* head, int val) {
        if (head->next == nullptr) {
            return nullptr;
        }
        if (head->next->val == val) {
            return _removeElements(head->next, val);
        }
        head->next->next = _removeElements(head->next, val);
        return head->next;
    }
};

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}